package com.example.secondassignment;

import com.example.secondassignment.R;

import android.app.Service;
import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.SoundPool;
import android.net.Uri;
import android.os.Binder;
import android.os.IBinder;

public class AlarmService extends Service {
	
	private static SoundPool soundPool = new SoundPool(1, AudioManager.STREAM_ALARM, 100);
	private static int soundID;
	private static int streamID;
	
	@Override
	public void onCreate(){
		super.onCreate();
		
		soundID = soundPool.load(this,R.raw.alarmsound,1);
	}

    public void playSound(){
    	streamID = soundPool.play(soundID, 1.f, 1.f, 1, 0, 1.f);
    }
    
    public void stopSound(){
    	soundPool.stop(streamID);
    }
    
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
    	System.out.println("onStartCommand(...)");
    	return Service.START_STICKY;
    	//return Service.START_NOT_STICKY;  
    }
    
    /**
     * Binding
     */
    private final IBinder binder = new AlarmBinder();
    
    @Override
    public IBinder onBind(Intent intent) {
    	return binder;
    }

    public class AlarmBinder extends Binder {
    	AlarmService getService() {
    		return AlarmService.this;
    	}
    }

}
